//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Research.ScientificWorkflow.TridentModel;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Input;
using System.Resources;
using System.Collections.ObjectModel;

namespace Microsoft.Research.ScientificWorkflow.UIDesigner
{
    class ConditionConnectorActivityElement : CompositeActivityElement
    {
        public ConditionConnectorActivityElement(CompositeActivityModel model, Dictionary<String, DataTypeModel> activityDataTypes)
            : base(model, activityDataTypes)
        {
            this.Width = 215;
            this.Loaded += new RoutedEventHandler(ConditionConnectorActivityElement_Loaded);
           
        }

        void ConditionConnectorActivityElement_Loaded(object sender, RoutedEventArgs e)
        {
            ConditionConnector conditionConnection = base.GetChildElements()[0] as ConditionConnector;
            conditionConnection.SizeChanged += new SizeChangedEventHandler(conditionConnection_SizeChanged);
        }

        void conditionConnection_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            this.Width = e.NewSize.Width + 15;
        }

        protected override ObservableCollection<ITridentUIElement> GetChildElements()
        {
            ObservableCollection<ITridentUIElement> baseChilds = base.GetChildElements();

            if (baseChilds.Count > 0)
            {
                ConditionConnector conditionConnection = base.GetChildElements()[0] as ConditionConnector;
                if (conditionConnection == null)
                {
                    return baseChilds;
                }

                return conditionConnection.ConditionChildren;
            }

            return base.GetChildElements();
        }
    }
}
